//
//  SplashViewController.swift
//  placepic
//
//  Created by elesahich on 2020/09/05.
//  Copyright © 2020 elesahich. All rights reserved.
//

import UIKit

class SplashViewController: UIViewController {

    var mTimer: Timer?
    var number: Int = 0
    
    @IBOutlet weak var welcomeLabel: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        ticktok()
        configureBackgroundView()
    }
   
    func configureBackgroundView() {
        view.backgroundColor = UIColor.warmPink
       
        welcomeLabel.font = .systemFont(ofSize: 32)
        welcomeLabel.textColor = UIColor.white
        welcomeLabel.text = "우리들끼리\n공유하는\n"
               
        let style = NSMutableParagraphStyle()
        style.lineSpacing = 18
        let attributedString = NSMutableAttributedString(string: welcomeLabel.text ?? "",
                                                         attributes: [NSAttributedString.Key.paragraphStyle: style,
        ])
        let attr = [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 32)]
        let attrs = NSMutableAttributedString(string: "최애장소",
                                              attributes: attr)
        attributedString.append(attrs)
        
        welcomeLabel.attributedText = attributedString
    }
   
    func ticktok() {
        if let timer = mTimer {
            if !timer.isValid {
                mTimer = Timer.scheduledTimer(timeInterval: 1,
                                              target: self,
                                              selector: #selector(timerCallback),
                                              userInfo: nil,
                                              repeats: true)
            }
        } else {
            mTimer = Timer.scheduledTimer(timeInterval: 1,
                                          target: self,
                                          selector: #selector(timerCallback),
                                          userInfo: nil,
                                          repeats: true)
        }
    }
    
    @objc
    func timerCallback() {
        number += 1
        if number == 3 {
            guard let nextVC = self.storyboard?.instantiateViewController(identifier: "newLoginNavigationController") else { return }
            nextVC.modalPresentationStyle = .fullScreen
            self.present(nextVC, animated: true, completion: nil)
            
        }
    }
}
